#include <REGX52.H>
#include "timer0.h"
#include "key.h"
#include "INTRINS.H"

unsigned char keyNumber, LEDMode;

void main()
{
	// 初始化LED灯
	P2 = 0xFE;
	timer0_init();
	
	while(1)
	{
		keyNumber = getKeyNumber();
		// 若独立按键按下
		if(keyNumber)
		{
			if(keyNumber == 1)
			{
				LEDMode++;
				// LEDMode在0和1之间切换
				if(LEDMode >= 2)
				{
					LEDMode = 0;
				}
			}
		}
	}
}

void Time0_Rountine() interrupt 1
{
	static unsigned int t0Count;
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	
	t0Count++; //t0Count计次，对中断频率进行分频
	// 分频1000次，大于1s，计数器重置为0
	if(t0Count >= 1000)
	{
		t0Count = 0;
		if(LEDMode == 0)
		{
			// 左移一位
			P2 = _crol_(P2, 1);
		}
		if(LEDMode == 1)
		{
			// 右移一位
			P2 = _cror_(P2, 1);
		}
	}
}

